package com.nguc.ngucpractice.service.impl;

import com.nguc.ngucpractice.common.entity.Result;
import com.nguc.ngucpractice.dao.LoginUserDao;
import com.nguc.ngucpractice.service.LoginService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Map;

@Service("LoginService")
public class LoginServiceImpl implements LoginService {
    @Resource
    private LoginUserDao loginUserDao;

    @Override
    public Result queryLoginUser(String userName, String password) {
        Result result = new Result();
        Map<String, Object> rtnMap = loginUserDao.queryLoginUser(userName);
        String realPwd = null;
        if (!CollectionUtils.isEmpty(rtnMap) && rtnMap.size() > 0) {
            realPwd = (String) rtnMap.get("password");
        }
        if (realPwd == null || "".equals(realPwd)) {
            result.setStatus("1");
            result.setData("没有该用户!");
            return result;
        } else if (!password.equals(realPwd)) {
            result.setStatus("1");
            result.setData("密码错误!");
            return result;
        }
        result.setStatus("0");
        result.setData(rtnMap);
        return result;
    }
}
